<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 吕旺平
  Date: 2019/10/29
  Time: 9:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
	<title>用户管理</title>
	<jsp:include page="/layout/_imports.jsp"></jsp:include>
</head>
<body>
<jsp:include page="/layout/_nav.jsp"></jsp:include>
<div class="container">
	<h2>用户管理</h2>

	<table class="table" style="text-align: center">
		<thead class="thead-dark">
		<tr>
			<th scope="col">ID</th>
			<th scope="col">用户名</th>
			<th scope="col">Email</th>
			<th scope="col">姓名</th>
			<th scope="col">手机号</th>
			<th scope="col">性别</th>
			<th scope="col">管理员</th>
			<th scope="col">操作</th>
		</tr>
		</thead>
		<tbody>
		<c:forEach items="${users}" var="u">
			<tr>
				<th scope="row">${u.id}</th>
				<td>${u.username}</td>
				<td>${u.email}</td>
				<td>${u.name}</td>
				<td>${u.mobile}</td>
				<td>${u.sex == 0 ? "女" : "男"}</td>
				<td>${u.isAdmin}</td>
				<td>
					<form action="${pageContext.request.contextPath}/user">
						<input type="hidden" name="state" value="delete">
						<input type="hidden" name="id" value="${u.id}">
						<a href="/user?state=edit&id=${u.id}" class="btn btn-primary">编辑</a>
						<button type="submit" class="btn btn-danger"
								onclick="return confirm('确认删除？')">删除
						</button>
					</form>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<c:if test="${not empty msg}">
		<div class="alert alert-danger">${msg}</div>
	</c:if>

	<a href="/admin/AddUser.jsp" class="btn btn-primary">添加用户</a>
</div>
</body>
</html>
